{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> start QUANTAXIS\n",
      "QUANTAXIS>> Selecting the Best Server IP of TDX\n",
      "QUANTAXIS>> === The BEST SERVER ===\n",
      " stock_ip 61.153.144.179 future_ip 61.152.107.141\n",
      "QUANTAXIS>> Welcome to QUANTAXIS, the Version is 1.0.13\n",
      "QUANTAXIS>>  \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``########`````##````````##``````````##`````````####````````##```##########````````#``````##``````###```##`````######`` \n",
      "  `##``````## ```##````````##`````````####````````##`##```````##```````##```````````###``````##````##`````##```##`````##` \n",
      "  ##````````##```##````````##````````##`##````````##``##``````##```````##``````````####```````#```##``````##```##``````## \n",
      "  ##````````##```##````````##```````##```##```````##```##`````##```````##`````````##`##```````##`##```````##````##``````` \n",
      "  ##````````##```##````````##``````##`````##``````##````##````##```````##````````##``###```````###````````##`````##`````` \n",
      "  ##````````##```##````````##``````##``````##`````##`````##```##```````##```````##````##```````###````````##``````###```` \n",
      "  ##````````##```##````````##`````##````````##````##``````##``##```````##``````##``````##`````##`##```````##````````##``` \n",
      "  ##````````##```##````````##````#############````##```````##`##```````##`````###########`````##``##``````##`````````##`` \n",
      "  ###```````##```##````````##```##```````````##```##```````##`##```````##````##`````````##```##```##``````##```##`````##` \n",
      "  `##``````###````##``````###``##`````````````##``##````````####```````##```##``````````##``###````##`````##````##`````## \n",
      "  ``#########``````########```##``````````````###`##``````````##```````##``##````````````##`##``````##````##`````##````## \n",
      "  ````````#####`````````````````````````````````````````````````````````````````````````````````````````````````````####` \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``````````````````````````Copyright``yutiansut``2017``````QUANTITATIVE FINANCIAL FRAMEWORK````````````````````````````` \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " \n"
     ]
    }
   ],
   "source": [
    "import QUANTAXIS as QA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n\\n我们主要试图在这个jupyter notebook 中重新阐述和定义QUANTAXIS的账户和组合的观点\\n\\n\\n在QUANTAXIS中,账户/策略作为一个基本单元,构建了投资的基础要素,但是去衡量策略/组合的优劣的时候,我们更倾向对于多个账户同时/批次的分析\\n\\n\\n譬如对于多因子的分析,单个因子可以看做是一个策略,而对于多个因子的组合管理,可能倾向于随机/不确定构建\\n\\n\\n\\n'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "\n",
    "我们主要试图在这个jupyter notebook 中重新阐述和定义QUANTAXIS的账户和组合的观点\n",
    "\n",
    "\n",
    "在QUANTAXIS中,账户/策略作为一个基本单元,构建了投资的基础要素,但是去衡量策略/组合的优劣的时候,我们更倾向对于多个账户同时/批次的分析\n",
    "\n",
    "\n",
    "譬如对于多因子的分析,单个因子可以看做是一个策略,而对于多个因子的组合管理,可能倾向于随机/不确定构建\n",
    "\n",
    "\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "r=QA.QA_fetch_account()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "account1=QA.QA_Account().from_message(r[0])\n",
    "\n",
    "account_list=[QA.QA_Account().from_message(x) for x in r]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[< QA_Account Acc_2j0HlMGD>,\n",
       " < QA_Account Acc_A6dO9fs3>,\n",
       " < QA_Account Acc_ivNguqh3>,\n",
       " < QA_Account Acc_Fl6bX5ke>]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "account_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "x=QA.QA_PortfolioView(account_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Acc_2j0HlMGD': < QA_Account Acc_2j0HlMGD>,\n",
       " 'Acc_A6dO9fs3': < QA_Account Acc_A6dO9fs3>,\n",
       " 'Acc_Fl6bX5ke': < QA_Account Acc_Fl6bX5ke>,\n",
       " 'Acc_ivNguqh3': < QA_Account Acc_ivNguqh3>}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "x.account_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "q=x.accounts[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000157</th>\n",
       "      <th>000333</th>\n",
       "      <th>000425</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000157  000333  000425\n",
       "date                                              \n",
       "2017-01-03   400.0   400.0   400.0   400.0   400.0\n",
       "2017-01-04   800.0   800.0   800.0   800.0   800.0\n",
       "2017-01-05     0.0     0.0     0.0     0.0     0.0\n",
       "2017-01-06   400.0   400.0   400.0   400.0   400.0\n",
       "2017-01-09     0.0     0.0     0.0     0.0     0.0\n",
       "2017-01-10   400.0   400.0   400.0   400.0   400.0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "\n",
    "pd.concat([account.daily_hold.set_index('date') for account in x.accounts]).groupby('date').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000157</th>\n",
       "      <th>000333</th>\n",
       "      <th>000425</th>\n",
       "      <th>account_cookie</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>Acc_2j0HlMGDAcc_A6dO9fs3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>Acc_2j0HlMGDAcc_A6dO9fs3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>Acc_2j0HlMGDAcc_A6dO9fs3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>Acc_2j0HlMGDAcc_A6dO9fs3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>Acc_2j0HlMGDAcc_A6dO9fs3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>Acc_2j0HlMGDAcc_A6dO9fs3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000157  000333  000425            account_cookie\n",
       "date                                                                        \n",
       "2017-01-03   200.0   200.0   200.0   200.0   200.0  Acc_2j0HlMGDAcc_A6dO9fs3\n",
       "2017-01-04   400.0   400.0   400.0   400.0   400.0  Acc_2j0HlMGDAcc_A6dO9fs3\n",
       "2017-01-05     0.0     0.0     0.0     0.0     0.0  Acc_2j0HlMGDAcc_A6dO9fs3\n",
       "2017-01-06   200.0   200.0   200.0   200.0   200.0  Acc_2j0HlMGDAcc_A6dO9fs3\n",
       "2017-01-09     0.0     0.0     0.0     0.0     0.0  Acc_2j0HlMGDAcc_A6dO9fs3\n",
       "2017-01-10   200.0   200.0   200.0   200.0   200.0  Acc_2j0HlMGDAcc_A6dO9fs3"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(q.daily_hold.set_index('date')+x.accounts[1].daily_hold.set_index('date'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime\n",
       "2017-01-03 09:30:00    1.98658e+06\n",
       "2017-01-04 09:30:00    1.97307e+06\n",
       "2017-01-05 09:30:00    2.00019e+06\n",
       "2017-01-06 09:30:00    1.98665e+06\n",
       "2017-01-09 09:30:00    2.00002e+06\n",
       "2017-01-10 09:30:00    1.98655e+06\n",
       "Name: cash, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.accounts[0].daily_cash.set_index('datetime').cash+x.accounts[2].daily_cash.set_index('datetime').cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000157</th>\n",
       "      <th>000333</th>\n",
       "      <th>000425</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "      <td>800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>400.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000157  000333  000425\n",
       "date                                              \n",
       "2017-01-03   400.0   400.0   400.0   400.0   400.0\n",
       "2017-01-04   800.0   800.0   800.0   800.0   800.0\n",
       "2017-01-05     0.0     0.0     0.0     0.0     0.0\n",
       "2017-01-06   400.0   400.0   400.0   400.0   400.0\n",
       "2017-01-09     0.0     0.0     0.0     0.0     0.0\n",
       "2017-01-10   400.0   400.0   400.0   400.0   400.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "r=pd.to_datetime(pd.Series(['2017-01-03','2018-01-02','2017-02-02','2015-01-08']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2015-01-08'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(r.min())[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   2017-01-03\n",
       "1   2017-01-03\n",
       "2   2017-01-03\n",
       "3   2017-01-03\n",
       "dtype: datetime64[ns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.to_datetime(pd.Series([account.start_date for account in x.accounts]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03 09:30:00</th>\n",
       "      <td>3.97317e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04 09:30:00</th>\n",
       "      <td>3.94613e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05 09:30:00</th>\n",
       "      <td>4.00038e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06 09:30:00</th>\n",
       "      <td>3.9733e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09 09:30:00</th>\n",
       "      <td>4.00003e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10 09:30:00</th>\n",
       "      <td>3.9731e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            cash\n",
       "datetime                        \n",
       "2017-01-03 09:30:00  3.97317e+06\n",
       "2017-01-04 09:30:00  3.94613e+06\n",
       "2017-01-05 09:30:00  4.00038e+06\n",
       "2017-01-06 09:30:00   3.9733e+06\n",
       "2017-01-09 09:30:00  4.00003e+06\n",
       "2017-01-10 09:30:00   3.9731e+06"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(sum([account.daily_cash.set_index('datetime').cash for account in x.accounts]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>datetime</th>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03 09:30:00</th>\n",
       "      <th>Acc_2j0HlMGD</th>\n",
       "      <td>993292</td>\n",
       "      <td>2017-01-03 09:30:00</td>\n",
       "      <td>2017-01-03</td>\n",
       "      <td>Acc_2j0HlMGD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04 09:30:00</th>\n",
       "      <th>Acc_2j0HlMGD</th>\n",
       "      <td>986533</td>\n",
       "      <td>2017-01-04 09:30:00</td>\n",
       "      <td>2017-01-04</td>\n",
       "      <td>Acc_2j0HlMGD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05 09:30:00</th>\n",
       "      <th>Acc_2j0HlMGD</th>\n",
       "      <td>1.00009e+06</td>\n",
       "      <td>2017-01-05 09:30:00</td>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Acc_2j0HlMGD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06 09:30:00</th>\n",
       "      <th>Acc_2j0HlMGD</th>\n",
       "      <td>993326</td>\n",
       "      <td>2017-01-06 09:30:00</td>\n",
       "      <td>2017-01-06</td>\n",
       "      <td>Acc_2j0HlMGD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09 09:30:00</th>\n",
       "      <th>Acc_2j0HlMGD</th>\n",
       "      <td>1.00001e+06</td>\n",
       "      <td>2017-01-09 09:30:00</td>\n",
       "      <td>2017-01-09</td>\n",
       "      <td>Acc_2j0HlMGD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10 09:30:00</th>\n",
       "      <th>Acc_2j0HlMGD</th>\n",
       "      <td>993275</td>\n",
       "      <td>2017-01-10 09:30:00</td>\n",
       "      <td>2017-01-10</td>\n",
       "      <td>Acc_2j0HlMGD</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           cash             datetime  \\\n",
       "datetime            account_cookie                                     \n",
       "2017-01-03 09:30:00 Acc_2j0HlMGD         993292  2017-01-03 09:30:00   \n",
       "2017-01-04 09:30:00 Acc_2j0HlMGD         986533  2017-01-04 09:30:00   \n",
       "2017-01-05 09:30:00 Acc_2j0HlMGD    1.00009e+06  2017-01-05 09:30:00   \n",
       "2017-01-06 09:30:00 Acc_2j0HlMGD         993326  2017-01-06 09:30:00   \n",
       "2017-01-09 09:30:00 Acc_2j0HlMGD    1.00001e+06  2017-01-09 09:30:00   \n",
       "2017-01-10 09:30:00 Acc_2j0HlMGD         993275  2017-01-10 09:30:00   \n",
       "\n",
       "                                          date account_cookie  \n",
       "datetime            account_cookie                             \n",
       "2017-01-03 09:30:00 Acc_2j0HlMGD    2017-01-03   Acc_2j0HlMGD  \n",
       "2017-01-04 09:30:00 Acc_2j0HlMGD    2017-01-04   Acc_2j0HlMGD  \n",
       "2017-01-05 09:30:00 Acc_2j0HlMGD    2017-01-05   Acc_2j0HlMGD  \n",
       "2017-01-06 09:30:00 Acc_2j0HlMGD    2017-01-06   Acc_2j0HlMGD  \n",
       "2017-01-09 09:30:00 Acc_2j0HlMGD    2017-01-09   Acc_2j0HlMGD  \n",
       "2017-01-10 09:30:00 Acc_2j0HlMGD    2017-01-10   Acc_2j0HlMGD  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q.daily_cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'account_cookie': ['Acc_2j0HlMGD',\n",
       "  'Acc_A6dO9fs3',\n",
       "  'Acc_ivNguqh3',\n",
       "  'Acc_Fl6bX5ke'],\n",
       " 'alpha': -0.8141026003658938,\n",
       " 'annualize_return': -0.0004582372482384578,\n",
       " 'benchmark_code': '000300',\n",
       " 'beta': 1.0,\n",
       " 'max_dropback': 0.00012000168002352033,\n",
       " 'portfolio_cookie': 'Portfolio_mJBeofIA',\n",
       " 'profit': -1.1000154002127616e-05,\n",
       " 'sharpe': -49.329896668511005,\n",
       " 'time_gap': 6,\n",
       " 'user_cookie': None,\n",
       " 'volatility': 0.0010228733619149807}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_Risk(x).message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
